<template>
  <div class="randoms-com">
    <el-card class="box-card">
      <div class="search">
        <div class="left">
          <span>关键字</span>
          <el-input  v-model="FormData.keyword" placeholder="根据编号搜索"></el-input>
        </div>
        <div class="right">
          <el-button @click="clearinpt">清空</el-button>
          <el-button type="primary" @click="onsearch">搜索</el-button>
        </div>
      </div>
      <el-alert :title="`数据一共${counts}条`" type="info" :closable="false" show-icon> </el-alert>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="编号" width="200">
        </el-table-column>
        <el-table-column label="题型" >
          <template #default="{row}">
            <span v-if="row.questionType === '1'">单选</span>
            <span v-else-if="row.questionType === '2'">多选</span>
            <span v-else-if="row.questionType === '3'">简答</span>
          </template>
        </el-table-column>
        <el-table-column  label="题目编码" width="200">
          <template #default="{row}">
            <div v-for="item in row.questionIDs" :key="item.number"><a style="color: #00A6FE;font-size: 14px;" href="#">{{ item.number }}</a></div>
          </template>
        </el-table-column>
        <el-table-column prop="addTime" label="录入时间" width="180">
        </el-table-column>
        <el-table-column prop="totalSeconds" label="答题时间(s)" >
        </el-table-column>
        <el-table-column prop="accuracyRate" label="正确率(%)" >
        </el-table-column>
        <el-table-column prop="userName" label="录入人" >
        </el-table-column>

        <el-table-column label="操作">
          <!-- <template slot-scope="scope"> -->
          <template #default="{row}">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              circle
              @click="delRandoms(row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="FormData.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="FormData.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="counts">
    </el-pagination>
    </el-card>

  </div>
</template>

<script>
import { getRandomsListRequest, deleteRandomsRequest } from '../../api/hmmm/questions-randoms'
export default {
  data () {
    return {
      input: '',
      counts: 0,
      tableData: [],
      FormData: {
        page: 1,
        pagesize: 5,
        keyword: ''
      }
    }
  },
  created () {
    this.getRandomsList()
  },
  methods: {
    clearinpt () {
      this.FormData.keyword = ''
    },
    onsearch () {
      this.getRandomsList()
    },
    async getRandomsList () {
      const res = await getRandomsListRequest(this.FormData)
      this.tableData = res.data.items
      this.counts = res.data.counts
      console.log(res)
    },
    handleSizeChange (val) {
      this.FormData.pagesize = val
      this.getRandomsList()
      // console.log(`每页 ${val} 条`)
    },
    handleCurrentChange (val) {
      this.FormData.page = val
      this.getRandomsList()
      // console.log(`当前页: ${val}`)
    },
    // 删除id
    async delRandoms (row) {
      console.log(row.id, '22000000000')
      const res = await deleteRandomsRequest({ id: row.id })
      this.$message.success('删除成功')
      this.getRandomsList()
      console.log(res)
    }
  }
}
</script>
<style>
</style>
<style scoped lang='scss'>
.randoms-com {
  padding: 20px;
  .box-card {
    padding: 20px;
    .search {
      display: flex;
      justify-content: space-between;
      .left {
        display: flex;
        align-items: center;
        span {
          width: 80px;
          font-size: 14px;
          color: #606266;
          font-weight: 700;
        }
      }
    }
    ::v-deep .el-alert {
      margin: 15px 0;
    }
    .el-pagination {
      margin-top: 15px;
      text-align: right;
    }
  }
}
</style>
